(function(){

    var JZMap,markers=[],
    mapWidth,mapHeight,timer=[],
    markSearchStatus=0,//默认未搜索
    MAPJSONCACHE=[],//地图数据缓存
    CACHEALLDISTRICTJSON=[],//小区全部数据缓存(包含加载更多数据)
    DISTRICTJSONCCHE=[],//小区数据缓存
    cacheClikObj="",//缓存点击处理遮罩栏目
    RESIZESTATUS=0,CacheClickZone=[],loadingMaping=false,//地图加载状态判断
    rightBoxWidth,isMiniMap=true,initedRoomStatus=0,zoneObj,timerPan,totalPage,gflag=false,gBound,
    _objM=$(".search-factors");
    isClickedEvt = false;
    /*浏览器检测/IE*/
    // // var Sys = {};
    // // var ua = navigator.userAgent.toLowerCase();
    // // window.ActiveXObject ? Sys.ie = ua.match(/msie ([\d.]+)/)[1] : 0;
    /*
     *@func:地图原型模块
     */
    var jMap=function(){}
    jMap.prototype={
        init:function(){
            var that=this;
            that.initMap();//初始化地图
        },
        
        /*
         *@func 函数节流，避免执行次数过快，性能优化
         * */
        resizeThrottleV2:function(fn, delay, mustRunDelay){
            var timer = null;
            var t_start;
            return function(){
                var context = this, args = arguments, t_curr = +new Date();
                clearTimeout(timer);
                if(!t_start){
                    t_start = t_curr;
                }
                if(t_curr - t_start >= mustRunDelay){
                    fn.apply(context, args);
                    t_start = t_curr;
                }
                else {
                    timer = setTimeout(function(){
                        fn.apply(context, args);
                    }, delay);
                }
            };
         },
        /*
         *@func:解析当前城市地图中心点
         * */
        getPoint:function(){
            var  that=this;
            var selectedCity = $('.city .text').text();
            var myGeo = new BMap.Geocoder();
            myGeo.getPoint(selectedCity, function(point){
                if (point) {
                    that.setMap(point,12);
                }else{
                    var point=new BMap.Point(0,0);
                    that.setMap(point,12);
                }
            });
        },
        /*
        *@func 窗口拉伸页面渲染
        */
        // resizeRenderMappage:function(){
        //     var that=jMap.prototype;
        //     mapWidth=$(window).width()-545;
        //     mapHeight=that.getWindowHeight()-90;
        //     if(mapWidth<475){
        //         mapWidth=475;
        //     }
        //     $(".map-page").css({
        //         height:mapHeight+"px"
        //     });
        //     $("#map").css({
        //         width:mapWidth+"px",
        //         height:mapHeight+"px",
        //         opacity:"1"
        //     });
        //     $("#rightColBox").css({
        //         height:mapHeight+"px"
        //     });

        //    $(".screen-trig").css({
        //       right:0,
        //       left:($("#rightColBox")[0].getBoundingClientRect().left-31)+"px"
        //    });
        //    $(".map-overlay").css({
        //         width:mapWidth+"px",
        //         height:mapHeight+"px"
        //    });
        //    //列表数据容器高度
        //    var rh=mapHeight-$(".col-search")[0].getBoundingClientRect().height-20;
        //    if(Sys.ie<9.0){
        //         rh=mapHeight-$('.bar-filter')[0].offsetHeight-20;
        //    }
        //    $(".result-list").css({
        //        height:rh+"px"
        //    });
        // },
        /*
         *@func:迷你地图展示事件
         * */
        // changeMiniscreenWandH:function(){
        //     var that=jMap.prototype;
        //     that.resizeRenderMappage();
        //     window.onresize=that.resizeThrottleV2(that.resizeRenderMappage, 200, 500);
        // },
        /*
        *@func 点击区域赋值右侧对应区域和小区名称
        */
        renderCurrentZone:function(area,circle,districName){
            if(area!=undefined && area!=""){
                $('.region').find('[data-value=' + area +']').trigger("click");
            }
        },
        /*
        *@func 区域状态重置条件
        */
        // resetSearch:function(){
        //     var _par=$("#zone-ops"),
        //         _sblin=$("#circle-ops");
        //     _par.val("选择区域").parent().next().val("0");
        //     _par.parent().next().next().find(".selected-li").removeClass("selected-li");
        //     _sblin.val("商圈").parent().next().val("0");
        //     _sblin.parent().next().next().html("");
        //     $("#keywords").val("");
        //     CacheClickZone=[];
        // },  
        /*
         *@func:请求地图渲染数据
         *@param 
         *  url  请求小区数据链接地址
         *  type 请求类型
         * */
        getZoneAjaxData:function(url,area,circle,districName){
            var that=this,data="",
            durl=map.url.community;
            that.renderCurrentZone(area,circle,districName);//渲染右侧选中数据
        },
        /*
         *@func:地图拖拽缩放重新渲染地图数据
         *@param 
         * */
        // getRealtimeData:function(url,bound){
        //   var that=this,data="";
        //  $.get(url,function(json){
        //      if(json.data.length>0){
        //          that.iniMapDataRender(json.data,2);
        //      }
        //  });
        // },
        /*
         *@func:地图结果数据渲染
         * */
        iniMapDataRender:function(json,type){
            var  that=this;
            // that.removeLoading();
            that.removeOverlay();
            if(type==1){
                //处理对应区域数据
                var markerArr = json,points=[];
                //你返回的数据格式
                for (var i = 0; i < markerArr.length; i++) {
                    var json=markerArr[i];
                    var txt = markerArr[i].area_string;
                    var pintx = markerArr[i].longitude;
                    var pinty = markerArr[i].latitude;
                    var count= markerArr[i].count;
                    var area_id= markerArr[i].area_id;
                    that.addOverlayToMap(new BMap.Point(pintx, pinty),txt,count,type,area_id,"","");//添加覆盖物
                    points.push(new BMap.Point(pintx, pinty));
                 }
                JZMap.setViewport(points);
            }else{
                //处理对应区域小区数据
                var markerArr = json,points=[];
                for (var i = 0; i < markerArr.length; i++) {
                    var json=markerArr[i];
                    var txt = markerArr[i].community_name;
                    var pintx = markerArr[i].longitude;
                    var pinty = markerArr[i].latitude;
                    var count= markerArr[i].count;
                    var area_id= markerArr[i].business_id;
                    var index_name=markerArr[i].index_name;
                    var community_id="";
                    community_id= markerArr[i].community_id;
                    that.addOverlayToMap(new BMap.Point(pintx, pinty),txt,count,type,area_id,community_id,index_name);
                    points.push(new BMap.Point(pintx, pinty));
                 }
                 var  _par=$("#map").find(".villageBox");
                 if(CacheClickZone.length>0){
                    $.each(_par,function(j,item){
                        if(CacheClickZone[0]== ($(item).attr("index_name")+$(item).attr("community_id"))){
                            $(item).parent().find(".light").removeClass("light");
                            $(item).addClass("light");
                            var _el=$(".light");
                            var zIndex=_el[0].style.zIndex<0?_el[0].style.zIndex*-1:_el[0].style.zIndex*1;
                            _el.css({"z-index":zIndex});
                        }
                    });
                 }
                JZMap.setViewport(points);
            }
        },
        /*
         *删除区域标记
         * */
        removeOverlay:function(){
            JZMap.clearOverlays();
        },

    /*
     *@func:当前屏幕内容高度获取   
     * */
    getWindowHeight:function(){
        return window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
    },

    /*
     *@func 地图高宽度赋值<全屏>  
     * */
    // changefullscreenWandH:function(){
    //     var that=jMap.prototype;
    //     mapWidth=$(window).width();
    //     mapHeight=that.getWindowHeight()-90;
    //     $(".map-page").css({
    //         height:mapHeight+"px"
    //     });
    //     $("#map").css({
    //         width:mapWidth+"px",
    //         height:mapHeight+"px"
    //     });
    //     $("#rightColBox").css({
    //         height:mapHeight+"px"
    //     });

    //   $(".screen-trig").css({
    //       right:0,
    //       left:"auto"
    //   });
    //     window.onresize=that.resizeThrottleV2(that.changefullscreenWandH, 200, 500);
    // },

    /*
    *@func初始区域渲染
    */
    setZoneData:function(type){
        var dt=map.area,that=this;
        that.iniMapDataRender(dt,type);
    },
    /*
    *@func  切换区域返回对应区域id
    */
    getCurrentArea:function(area_id){
        var dt=map.area,that=this,data;
        $.each(dt,function(i,o){
            if(area_id==o.area_id){
                data=o;
            }
        });
        return data;
    },
    /*
    *@func  重置地图选项
    */
    // resetMap:function(point,zoom){
    //     if(timerPan!=null){
    //         clearTimeout(timerPan);
    //     }
    //     timerPan=window.setTimeout(function(){
    //         // JZMap.centerAndZoom(point,15);
    //     },500);
    // },
    // addMarker:function(point){  // 创建图标对象     
    //   var myIcon = new BMap.Icon("http://api.map.baidu.com/mapCard/img/location.gif",   
    //       new BMap.Size(14, 23), {            
    //        anchor: new BMap.Size(7, 25)       
    //       });        
     // 创建标注对象并添加到地图     
     //  var marker = new BMap.Marker(point, {icon: myIcon});      
     //  JZMap.addOverlay(marker);      
     // },
    /*
     *@func 获取四周边界坐标位置
     * */
     getReactBox:function(){
        var  that=this;
        var ne = {};
        var sw = {};
        var space = 0;
            var size = JZMap.getSize();
            ne = JZMap.pixelToPoint(new BMap.Pixel(space, space));
            sw = JZMap.pixelToPoint(new BMap.Pixel(size.width - space, size.height - space));
        
        var x1 = ne.lat.toFixed(4);
        var y1 = ne.lng.toFixed(4);
        var x2 = sw.lat.toFixed(4);
        var y2 = sw.lng.toFixed(4);
        
        var ret = {
            x1: x1,
            y1: y1,
            x2: x2,
            y2: y2
        };
        
        return ret;     
     },
    /*
     *@func 设定地图<全屏>     
     * */
    setMap:function(point,zoom){
        var that=this,evtTimer=[];
        JZMap.centerAndZoom(point, zoom);
        JZMap.enableScrollWheelZoom();
        JZMap.setMinZoom(9);

        that.setZoneData(1);
        //滚轮 
        JZMap.addEventListener("zoomstart",function(){
            flag=false;
            if(evtTimer!=null){
                clearTimeout(evtTimer);
            }
        },false);

        // 滚轮
        JZMap.addEventListener("zoomend",function(){
            if(isClickedEvt == true){
                isClickedEvt = false;
                gflag=false;
                return;
            }
            isClickedEvt = true;
            // that.genLoading();
            that.removeOverlay();
            var bound=that.getReactBox();
            var zoom=this.getZoom();
            // 节流
            evtTimer=setTimeout(function(){
                that.iniTimerStack(zoom,bound,"zoomend");
            },800);
        },false);

        //拖拽start
        JZMap.addEventListener("dragstart",function(){
            gflag=false;
            if(evtTimer!=null){
                clearTimeout(evtTimer);
            }
        },false);

        //拖拽end
        JZMap.addEventListener("dragend",function(){
            // that.genLoading();
            // that.removeOverlay();
            var bound=that.getReactBox();
            var zoom=this.getZoom();
            evtTimer=setTimeout(function(){
                that.iniTimerStack(zoom,bound,"dragend");
            },800);
        },false);
    },
    /*
    *@func 设定执行时间间隔
    */
    iniTimerStack:function(zoom,bound){
        var that=this;
        // var mustRunDelay=500,//执行时间间隔
        //  delay=200;//延迟执行时间
        // var timer = null;
     //    var t_start,t_curr = +new Date();
  //       clearTimeout(timer);
  //       if(!t_start){
  //           t_start = t_curr;
  //       }
  //       if(t_curr - t_start >= mustRunDelay){
        //  that.resetMapData(zoom,bound);
  //           t_start = t_curr;
  //       }else {
  //           timer = setTimeout(function(){
  //            that.resetMapData(zoom,bound);
  //           }, delay);
  //       }
        that.resetMapData(zoom,bound);
    },
    /*
    *@func 显示地图加载层
    */
    // genLoading:function(){
        // $(".map-overlay").show();
    // },

    /*
    *@func 地图加载层
    */
    // removeLoading:function(){
    //     $(".map-overlay").hide();
    // },
    /*
    *@func 地图重置,发送请求
    */
    resetMapData:function(zoom,bound,flag){
        var that=this;
        that.getMapAreas(zoom,bound,flag);
        // that.getHouseList();
    },

    /*
    *@func 获取地图显示小区数据
    */
    getMapAreas:function(zoom,bound,flag){
        var url=map.url.community,that=this,
            param="";
        //自己的数据
        var area_id=$('.region').find('.selected').data('value').replace(/ /g,'')
        var business_id=$('.business').find('.selected').data('value').replace(/ /g,'')
        var keywords=$('.code').val().replace(/ /g,'')
        //达到可以渲染小区数据临界值
        // if(zoom>12){
            if(area_id==0 && business_id==0 && keywords==""){
                url=url.replace("[:business]","")
                    .replace("[:area]","")
                    .replace("[:x1]",bound.x1)
                    .replace("[:y1]",bound.y1)
                    .replace("[:x2]",bound.x2)
                    .replace("[:y2]",bound.y2);
            }else{
                var a="",b="",c="",d="";
                if(flag!=false){
                    var a=bound.x1,b=bound.y1,c=bound.x2,d=bound.y2;
                }
                url=url.replace("[:business]",business_id)
                    .replace("[:area]",area_id)
                    .replace("[:x1]",a)
                    .replace("[:y1]",b)
                    .replace("[:x2]",c)
                    .replace("[:y2]",d);
            }
            gBound=bound;
           // that.getRealtimeData(url,bound);
            var data="";
            $.get(url,function(json){
                // isClickedEvt = true;
                if(json.data.length>0){
                    that.iniMapDataRender(json.data,2);
                }
                    that.getHouseList();
            });
        // }
      //   else{
      //    that.resetSearch();
            // that.setZoneData(1);
      //   }
    },
    /*
    *@func 全屏/小屏切换
    */
    // bindFulltrig:function(){
    //     var  that=this;
    //     $(".screen-trig").off().on("click",function(){
    //         var  cur=$(this);
    //         if(!cur.hasClass("full")){
    //              isMiniMap=false;
    //              $("#rightColBox").hide();
    //              cur.addClass("full");
    //              that.changefullscreenWandH();
    //         }else{
    //             isMiniMap=true;
    //             $("#rightColBox").show();
    //             that.changeMiniscreenWandH();
    //             cur.removeClass("full");
    //         }   
    //     });
    // },
    /*
    *@func 显示对应全屏/退出全屏图标
    *
    */
    // getToolbarStatus:function(){
    //     if(isMiniMap==false){
    //         $(".screen-trig").removeClass("full");
    //     }else{
    //         $(".screen-trig").addClass("full");
    //     }
    // },
        /*
        *@ 添加自定义覆盖遮罩物
        *@ 自定义样式
        *
        */
    addOverlayToMap:function(point,text,count,type,areaId,communityId,indexName){
            var ep=this;
            function ComplexCustomOverlay(point,text,count,type,areaId,communityId){
                this._point = point;
                this._text = text;
                this._count=count;
                this._type=type;
                this._areaId=areaId;
                this._communityId=communityId;
                this._indexName=indexName;
            }
            ComplexCustomOverlay.prototype = new BMap.Overlay();
            ComplexCustomOverlay.prototype.initialize = function(map,type){
                this._map = JZMap;
                var div = this._div = document.createElement("div");
                div.style.position = "absolute";
                div.style.cursor="pointer";
                div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);
                div.style.MozUserSelect = "none";

                //鼠标移入
                div.onmouseover = function(){
                    // this.style.background = "#ffd7dd";
                    // arrow.style.background='url(http://img-cdn.jooozo.cn/img/map_arrow_active.png) no-repeat 0 0';
                    var cur=$(this);
                    if(cur.hasClass("light")){
                        var zIndex=cur[0].style.zIndex<0?cur[0].style.zIndex*-1:cur[0].style.zIndex*1;
                        cur.css({"z-index":zIndex});
                    }else{
                        cur.addClass("active");
                        var zIndex=BMap.Overlay.getZIndex(cur.attr("lat"))*-1;
                        cur.css({"z-index":zIndex});
                        if($(".light").length>0){
                            var zIndex=$(".light")[0].style.zIndex*-1;
                            $(".light").css({"z-index":zIndex});
                        }
                    }
                    
                }
                //鼠标移出
                div.onmouseout = function(){
                    // this.style.background = "#fff";
                    // arrow.style.background='url(http://img-cdn.jooozo.cn/img/map_arrow.png) no-repeat 0 0';
                    var  cur=$(this);
                    $(cur).removeClass("active");
                    var zIndex=this.style.zIndex*-1;
                    $(cur).css({"z-index":zIndex});
                    if($(".light").length>0){
                        var zIndex=$(".light")[0].style.zIndex<0 ? $(".light")[0].style.zIndex*-1:$(".light")[0].style.zIndex*1;
                        $(".light").css({"z-index":zIndex});
                    }
                }
                //区域类型
                if(this._type==1){
                    div.className="zonebox";
                    div.lng=this._point.lng;
                    div.lat=this._point.lat;
                    div.setAttribute("lng",this._point.lng);
                    div.setAttribute("lat",this._point.lat);
                    div.setAttribute("area_id",this._areaId);
                    div.style.marginTop="-40px";
                    div.style.marginLeft="-60px";
            
                    var h3 = this._h3 = document.createElement("h3");
                    var p=this._p=document.createElement("p");
                    var span=this._span=document.createElement("span");
                    var unit=this._unit=document.createElement("span");
                    span.style.margin="0 3px";
                    div.appendChild(h3);
                    div.appendChild(p);
                    p.appendChild(span);
                    p.appendChild(unit);
                    h3.appendChild(document.createTextNode(this._text)); 
                    span.appendChild(document.createTextNode(this._count)); 
                    unit.appendChild(document.createTextNode("间")); 
            
                    /*IE事件绑定*/
                    if(Sys.ie){
                        div.onclick=function(){
                            $(".zonebox").removeClass("active");
                            $(this).addClass("active");
                            var lng=$(this).attr("lng"),lat=$(this).attr("lat"),
                                area_id=$(this).attr("area_id");
                            ep.removeOverlay();
                            jMap.prototype.getZoneAjaxData("",area_id,"","");//渲染对应层级数据
                        }
                    }else{
                        div.addEventListener("click",function(){
                            $(".zonebox").removeClass("active");
                            $(this).addClass("active");
                            var lng=$(this).attr("lng"),lat=$(this).attr("lat"),
                                area_id=$(this).attr("area_id");
                            ep.removeOverlay();
                            jMap.prototype.getZoneAjaxData("",area_id,"","");//渲染对应层级数据
                        });
                    }
                }else{
                    //小区类型
                    div.className="villageBox";
                    div.lng=this._point.lng;
                    div.lat=this._point.lat;
                    div.area_id=this._areaId;
                    div.community_id=this._communityId;
                    div.setAttribute("lng",this._point.lng);
                    div.setAttribute("lat",this._point.lat);
                    div.setAttribute("area_id",this._areaId);
                    div.setAttribute("community_id",this._communityId);
                    div.setAttribute("index_name",this._indexName);

            
                    var span = this._span = document.createElement("span");
                    span.className="business_name";
                    var i=this._i=document.createElement("i");
                    var unit=this._unit=document.createElement("span");
                    div.appendChild(span);
                    div.appendChild(i);
                    div.appendChild(unit);
                    span.appendChild(document.createTextNode(this._text)); 
                    i.appendChild(document.createTextNode(this._count)); 
                    unit.appendChild(document.createTextNode("间")); 
                
                    var that = this;
                    var arrow = this._arrow = document.createElement("div");
                    div.appendChild(arrow);
                
                    /*IE事件绑定*/
                    if(Sys.ie){
                        div.onclick=function(){
                            var cur=$(this);
                             if(!cur.hasClass("light")){
                                if($(".light").length>0){
                                    var zIndex=$(".light")[0].style.zIndex<0 ? $(".light")[0].style.zIndex*1:$(".light")[0].style.zIndex*-1;
                                    cur.parent().find(".light").css({"z-index":zIndex});
                                }
                                cur.parent().find(".light").removeClass("light");
                                cur.parent().find(".active").removeClass("active");
                                cur.addClass("light");
                                cacheClikObj="";//清空
                                cacheClikObj=cur;
                                var lng=$(this).attr("lng");
                                var lat=$(this).attr("lat");
                                var community_id=$(this).attr("community_id");
                                var area_id=$(this).attr("area_id");
                                var spoint=new BMap.Point(lng,lat);
                                var indexName=this.getAttribute("index_name");
                                $(_objM).attr("community-id",community_id);
                                CacheClickZone=[];
                                CacheClickZone.push(indexName+community_id);
                               // if(isMiniMap==false){
                               //      $(".screen-trig").removeClass("full");
                               //      isMiniMap=true;
                               //      $("#rightColBox").show();
                               //      ep.changeMiniscreenWandH();
                                    // JZMap.setCenter(spoint);
                               // }
                                $("#keywords").val(cur.find(".business_name").text());
                                JZMap.setCenter(spoint);
                                jMap.prototype.getHouseList();
                             }
                        };
                    }else{
                        div.addEventListener("click",function(){
                            var cur=$(this);
                            if(!cur.hasClass("light")){
                                if($(".light").length>0){
                                    var zIndex=$(".light")[0].style.zIndex<0 ? $(".light")[0].style.zIndex*1:$(".light")[0].style.zIndex*-1;
                                    cur.parent().find(".light").css({"z-index":zIndex});
                                }
                                cur.parent().find(".light").removeClass("light");
                                cur.parent().find(".active").removeClass("active");
                                cur.addClass("light");
                                cacheClikObj="";//清空
                                cacheClikObj=cur;
                                var loc=new BMap.Point(this.getAttribute("lng"),this.getAttribute("lat"));
                                var community_id=this.getAttribute("community_id");
                                var area_id=this.getAttribute("area_id"),
                                    indexName=this.getAttribute("index_name");
                                $(_objM).attr("community-id",community_id);
                                CacheClickZone=[];
                                CacheClickZone.push(indexName+community_id);
                               // if(isMiniMap==false){
                               //      $(".screen-trig").removeClass("full");
                               //      isMiniMap=true;
                               //      $("#rightColBox").show();
                               //      ep.changeMiniscreenWandH(1);
                                    // console.log(loc);
                                    // JZMap.setCenter(loc);
                               // }
                                $("#keywords").val(cur.find(".business_name").text());
                                JZMap.setCenter(loc);
                                jMap.prototype.getHouseList();
                            }
                        });
                    }
                }
                JZMap.getPanes().markerPane.appendChild(div);
                //修正误差
                if(div.className=="villageBox"){
                    if(Sys.ie<9.0){
                        $(".villageBox").css({
                            "margin-top":$(".villageBox").height(),
                            "margin-left":$(".villageBox").width()
                        });
                    }else{
                        div.style.marginTop=div.getBoundingClientRect().height*(-1)+"px";
                        div.style.marginLeft=(div.getBoundingClientRect().width/2)*(-1)+"px";
                    }
                }
                return div;
        }
        //添加标注
        ComplexCustomOverlay.prototype.draw = function(){
            var JZMap = this._map;
            // console.log(this._div.offsetWidth / 2);
            var pixel = JZMap.pointToOverlayPixel(point);
            this._div.style.left = (pixel.x) + "px";
            this._div.style.top = (pixel.y) + "px";
        }
        ComplexCustomOverlay.prototype.addEventListener = function(event,fun){//点击事件
            this._div['on'+event] = fun;
        }
        /*添加覆盖物到地图上*/
        var marker=new ComplexCustomOverlay(new BMap.Point(point.lng,point.lat),text,count,type,areaId,communityId,indexName);
        JZMap.addOverlay(marker);
    },
    /*
     *@func:事件绑定
     * @desc:
     * */
    bind:function(){
        var  that=this;
        // 显示下拉
        $('.sel-inner').click(function(){
            $('.drop-menu').hide();
            $(this).siblings('.drop-menu').show();
        });
        
        // 下拉选择以后的操作
        $('.drop-menu').on( "click", "li", function() {
            var sel_code = $(this).parent().siblings('input.sel-code');
            var code = $(this).attr('data-selVal');
            
            // Ajax获得城市列表
            if (sel_code.attr('name') == 'area_id') {
                $('input[name=city_id]').val(0);
                $.get('./ajaxBusiness', {'area': code}, function(json){
                    // 请求成功
                    if (json.status == 0) {
                        if (json.data.length == 0) {
                            $('input[name=business_id]').parent().hide();
                            return true;
                        }
                        
                        $('input[name=business_id]').parent().show();
                        
                        var lis = [];
                        for (var k in json.data) {
                            var li = '<li data-selVal="' + k + '">' + json.data[k] + '</li>';
                            lis.push(li);
                        }
                        $('input[name=business_id]').siblings('.drop-menu').empty().append(lis.join("\n"));
                        var ipt = $('input[name=business_id]').siblings('.sel-inner').children('input');
                        ipt.val(ipt.attr('data-default'));
                    } else if (json.status == 1) {
                        alert(json.msg.data);
                    }
                });
                var area_id=this.getAttribute('data-selval');
                if(area_id==0){
                    window.location.href=window.location.href;
                }else{
                var json=that.getCurrentArea(area_id);
                if(json==undefined || json=="" || json==null){
                    that.removeOverlay();
                }
                $("input[name='area_id']").val(area_id);
                var bound=that.getReactBox();
                isClickedEvt = true;
                gflag=true;//标记是否传参状态
                var flag=false;
                that.resetMapData("",bound,flag);
                
                // console.log(json);
                // var lng=json.longitude,
                    // lat=json.latitude;

                // var point=new BMap.Point(lng, lat);
                // var zoom = 15;
                // that.resetMap(point,zoom);

                // var timer = setInterval(function(){
                //  if (JZMap.getZoom() < zoom) return true;
                    // var data="",
                 //     durl=map.url.community;
              //    durl=durl.replace("[:business]","")
              //        .replace("[:area]",area_id)
              //        .replace("[:x1]","")
              //        .replace("[:y1]","")
              //        .replace("[:x2]","")
              //        .replace("[:y2]","");
                    // $.get(durl,data,function(json){
                    //  if(json.data.length>0){
                    //      that.iniMapDataRender(json.data,2);
                    //      that.getHouseList();
                    //  }
                    // });
                //  clearInterval(timer);

                // },100);
                }

            }
            $(this).parent().siblings('.sel-inner').children('input').val( $(this).html());
            sel_code.val(code);
            $(this).addClass('selected-li');
            $(this).siblings().removeClass('selected-li');
        });
        
        // 点击其他地方隐藏下拉
        $('body').click(function(event){
            var filter = ['sel-inner', 'sel-ipt', 'trig-down', 'drop-menu'];
            for (var i = 0; i < filter.length; i++) {
                if ($(event.target).hasClass(filter[i])) return true;
            }
            
            $('.drop-menu').hide();
        });
        // 条件筛选
        var conditionDictionary = ['price', 'type', 'configuration'];
        for (var i = 0; i < conditionDictionary.length; i++) {
            var key = conditionDictionary[i];
            $('[role=' + key + '] dd > a').click(function(){
                var parent = $(this).parent().parent().parent().parent();
                if (parent.attr('role') == 'configuration') {
                    if ($(this).hasClass('active')) $(this).removeClass('active')
                    else $(this).addClass('active')
                } else {
                    $(this).parent().siblings('dd').children().removeClass('current');
                    $(this).addClass('current');
                }
                that.getHouseList();
            });
        }

        $("#getMapData").click(function(){
            that.getHouseList();
        });
    },
    /*
    *@func 获取房源列表
    */
    getHouseList:function(page){
        var  that=jMap.prototype;
        // var bound=that.getReactBox();
        var bound=gBound;
        if (bound == undefined) bound = {};
        // if(!!!page) page=0;
        // page+=1;
        // $("#jpagiantion").html("");
        // $("#list-wrap").html("").hide();
        // $("#pagiantion,.sumLine").hide();
        var  el=$('.config-row').find(".active"),configuration="";
        $.each(el,function(i,o){
            if(i==0){
                configuration+=$(o).attr("data-id");    
            }else{
                configuration+=","+$(o).attr("data-id");
            }
        });
        var community_id="",
            area_id=$(".sel-wrap").find("input[name='area_id']").val(),
            business_id=$(".sel-wrap").find("input[name='business_id']").val(),
            type=$(".type-li").find(".current").attr("data-id"),
            price=$(".li_price").find(".current").attr("data-id"),
            index_name=$(".villageBox.light").attr("index_name")?$(".villageBox.light").attr("index_name"):"",
            configuration=configuration,
            x1=bound.x1,
            y1=bound.y1,
            x2=bound.x2,
            y2=bound.y2,
            keyword=$("#keywords").val().replace(/ /g,"");

        var isComunity=$(".villageBox.light").length;
        if(isComunity>0){
            community_id=$(".villageBox.light").attr("community_id");
            x1="";
            y1="";
            x2="";
            y2="";
            keyword="";
        }
        if(area_id!=0 && gflag==true){
            x1="";
            y1="";
            x2="";
            y2="";
        }
        var hurl=map.url.house;
        hurl=hurl.replace("[:page]",page)
                 .replace("[:area]",area_id)
                 .replace("[:business]",business_id)
                 .replace("[:type]",type)
                 .replace("[:price]",price)
                 .replace("[:index_name]",index_name)
                 .replace("[:configuration]",configuration)
                 .replace("[:x1]",x1)
                 .replace("[:y1]",y1)
                 .replace("[:x2]",x2)
                 .replace("[:y2]",y2)
                 .replace("[:community_id]",community_id)
                 .replace("[:keyword]",keyword);
        $.get(hurl,"",function(json){
            if(json.list && json.list.length>0){
                $("#pagiantion,.sumLine").show();
                $(".empty-wrap").hide();
                $("#totle-number").text(json.count);
                var endNum=((page>=1)?(20+(page-1)*20):(20+(page-1)*20)-1);
                var range=(page-1)*20+1+"~"+ (endNum < json.count ? endNum : json.count);
                if(json.count%20==0){
                    totalPage=json.count/20;
                }else{
                    totalPage=parseInt(json.count/20)+1;
                }
                $("#current-range").text(range);
                that.iniPagination(json.count,"#jpagiantion",that.getHouseList,20,page-1);
                that.renderListTemplate(json,page);
            }else{
                $(".empty-wrap").show();
                $("#jpagiantion").html("");
                $("#list-wrap").html("").hide();
                $("#pagiantion,.sumLine").hide();
            }
        });
    },

    /*
    *@func 页面模板渲染
    */
    // renderListTemplate:function(json){
    //     var temp=template("list-temp",json);
    //     $("#list-wrap").html(temp).show();
    // },
    /*
    *@func 绑定分页插件
    */
    // iniPagination:function(t,id,func,size,cpage){
    //     if(!!!func){
    //         func=function(){};
    //     }
    //     if(!!!size){
    //         size=10;
    //     }
    //     if(!!!cpage){
    //         cpage=0;
    //     }
    //     $(id).pagination(t, {
    //         callback: func,
    //         prev_text: '<',
    //         next_text: '>',
    //         items_per_page:size,
    //         num_display_entries:3,
    //         current_page:cpage,
    //         num_edge_entries:3,
    //         link_to:"javascript:;"
    //     });
    // },
    initMap:function(){
        var that=this;
        // that.changeMiniscreenWandH();
        JZMap=new BMap.Map("map");
        window.JZMap=JZMap;
        that.getPoint();
        // that.bindFulltrig();
        // that.bind();
        // that.setZoneData(1);
        // that.getHouseList();
         // that.iniPagination(10000,"#jpagiantion",that.getHouseList,20,0);
        }
    };

if(Sys.ie<9.0){
    $(document).ready(function(){
        var jmp=new jMap();
        jmp.init();
    });
}else{
    document.addEventListener('DOMContentLoaded',function(){
        var jmp=new jMap();
        jmp.init();
    },false);
}
})();
